//方法一：暴力求
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
int kthToLast(struct ListNode* head, int k) {
    struct ListNode* next = head;
    int count = 1;
    while(next->next){
        next = next->next;
        count++;
    }
    while((count - k) > 0){
        head = head->next;
        count--;
    }
    return head->val;
}

//方法二：快慢指针(快指针先走k步，然后快慢指针一起走，直到结束，此时慢指针所指向的值就是目标值)
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
int kthToLast(struct ListNode* head, int k) {
    struct ListNode* fast = head;
    struct ListNode* slow = head;
    while(k--){
        fast = fast->next;
    }
    while(fast){
        slow = slow->next;
        fast = fast->next;
    }

    return slow->val;
}